﻿namespace Cmn
{
    using System;
    using System.Text;

    public class Rand
    {
        public static int _RandIndex = 0;

        public static string GetGuid()
        {
            return Guid.NewGuid().ToString();
        }

        public static string RndCode(int length)
        {
            if (_RandIndex >= 0xf4240)
            {
                _RandIndex = 1;
            }
            char[] chArray = new char[] { 
                'a', 'b', 'd', 'c', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'p', 'r', 
                'q', 's', 't', 'u', 'v', 'w', 'z', 'y', 'x', '0', '1', '2', '3', '4', '5', '6', 
                '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 
                'N', 'Q', 'P', 'R', 'T', 'S', 'V', 'U', 'W', 'X', 'Y', 'Z'
             };
            StringBuilder builder = new StringBuilder();
            Random random = new Random(DateTime.Now.Millisecond + _RandIndex);
            for (int i = 0; i < length; i++)
            {
                builder.Append(chArray[random.Next(0, chArray.Length)].ToString());
            }
            return builder.ToString();
        }

        public static string RndDateStr()
        {
            if (_RandIndex >= 0xf4240)
            {
                _RandIndex = 1;
            }
            DateTime now = DateTime.Now;
            string str = null;
            string str2 = now.Year.ToString();
            string str3 = now.Month.ToString();
            if (str3.Length < 2)
            {
                str3 = "0" + str3;
            }
            string str4 = now.Day.ToString();
            if (str4.Length < 2)
            {
                str4 = "0" + str4;
            }
            string str5 = now.Hour.ToString();
            if (str5.Length < 2)
            {
                str5 = "0" + str5;
            }
            string str6 = now.Minute.ToString();
            if (str6.Length < 2)
            {
                str6 = "0" + str6;
            }
            string str7 = now.Second.ToString();
            if (str7.Length < 2)
            {
                str7 = "0" + str7;
            }
            string str9 = str;
            str = str9 + str2 + str3 + str4 + str5 + str6 + str7;
            Random random = new Random(DateTime.Now.Millisecond + _RandIndex);
            return (str + random.Next(100, 0x3e7).ToString());
        }

        public static string RndLetter(int length)
        {
            if (_RandIndex >= 0xf4240)
            {
                _RandIndex = 1;
            }
            char[] chArray = new char[] { 
                'a', 'b', 'd', 'c', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'p', 'r', 
                'q', 's', 't', 'u', 'v', 'w', 'z', 'y', 'x', '_', 'A', 'B', 'C', 'D', 'E', 'F', 
                'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'Q', 'P', 'R', 'T', 'S', 'V', 'U', 'W', 
                'X', 'Y', 'Z'
             };
            StringBuilder builder = new StringBuilder();
            Random random = new Random(DateTime.Now.Millisecond + _RandIndex);
            for (int i = 0; i < length; i++)
            {
                builder.Append(chArray[random.Next(0, chArray.Length)].ToString());
            }
            return builder.ToString();
        }

        public static string RndNum(int length)
        {
            if (_RandIndex >= 0xf4240)
            {
                _RandIndex = 1;
            }
            char[] chArray = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
            StringBuilder builder = new StringBuilder();
            Random random = new Random(DateTime.Now.Millisecond + _RandIndex);
            for (int i = 0; i < length; i++)
            {
                builder.Append(chArray[random.Next(0, 9)].ToString());
            }
            return builder.ToString();
        }
    }
}

